#ifndef GLOBALOBSERVER_H
#define GLOBALOBSERVER_H

#include <QObject>
#include "observerapater.h"
#include "../common.h"

struct RelationData
{
    ObserverMsgType msg_type;
    QObject *reciver;
    ObserverApater *observer_apater;
};

/*全局观察者类
* 实现不同层级的窗口对象注册不同类型消息，并且任意对象触发某一种类型的消息
*/
class GlobalObserver : public QObject
{
    Q_OBJECT
public:

    //恶汉单例,返回静态对象的引用
    static GlobalObserver* getGlobalObserver();

    //绑定
    void attach(ObserverMsgType msg_type, QObject *reciver, const char *method);
    //解绑
    void detach(ObserverMsgType msg_type, const QObject* reciver);
    //触发
    void notify(ObserverMsgType msg_type);
    void notify(ObserverMsgType msg_type, int screen_id, int partition_id, int layout_id, int item_id, QString cab_pos_item_str);
    void notify(ObserverMsgType msg_type, int screen_id, int partition_id, int layout_id);
    void notify(ObserverMsgType msg_type, int screen_id, int partition_id);
    void notify(ObserverMsgType msg_type, int screen_id);


private:
    explicit GlobalObserver(QObject *parent = 0);
    ~GlobalObserver();
    static GlobalObserver instance;
    QList<RelationData*> m_relation_list;
};

#endif // GLOBALOBSERVER_H
